/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.game.math.view.action;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.util.ResourceBundle;
import javax.swing.AbstractAction;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import org.game.math.view.domain.Examination;

/**
 *
 * @author nmduc
 */
class CheckGameAction(name:String) extends AbstractAction(name) {

  def this() = {
    this(CheckGameAction.bundle.getString("item.menu.name"));
  }
  override def actionPerformed(ae:ActionEvent):Unit = {
    val examination:Examination  = Examination.getInstance();
    val points:Long = examination.calculatePointsAndStopEditing();
    val index:Int = points.intValue;
    val randomIndex:Int = (System.currentTimeMillis() % 3 + 1).intValue;
    var markIndex = index/2;
    if(markIndex==0) {
      markIndex = 1;
    }
    JOptionPane.showMessageDialog(ae.getSource().asInstanceOf[Component], 
                                  CheckGameAction.bundle.getString("you.have") +" "+ points + " " + CheckGameAction.bundle.getString("points"),
                                  CheckGameAction.bundle.getString("pointsTitle"), JOptionPane.INFORMATION_MESSAGE,
                                  CheckGameAction.IMAGES.get(markIndex).get(randomIndex));
  }
}

object CheckGameAction {
  private val bundle:ResourceBundle = ResourceBundle.getBundle("org.game.math.view.action.CheckGameAction");
  private final var IMAGES:Map[Int, Map[Int, Icon]] = Map();

  for (i <- 1 to 5) {
    var icons:Map[Int, Icon]  = Map();
    for (j <- 1 to 3) {
      val imageIconKey:String = "point." + i + ".image" + j;
      icons += j -> new ImageIcon(CheckGameAction.getClass.getResource(bundle.getString(imageIconKey)));
    }
    IMAGES += i -> icons;
  }
}